var http = require('../../utils/http.js');
var util = require('../../utils/util.js');
var unionid = wx.getStorageSync('thisCode');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabFlag:true,
    imgUrl:http.imgUrl,
    exchangeArr:['全部','已过期','已使用','可使用'],
    exchangeIndex:0,
    cardArr:[],
    data:{
      name:'暂无全部的优惠券信息'
    },
    aaFlag:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    if(options.payEwm){
      this.setData({payEwm:options.payEwm})
    }
    let scrollH = Number(util.nowPhoneWH()[1])-(70+60);
    this.setData({scrollH:scrollH})
    this.cardBagFn(0)
  },
  cardBagFn(type){
    var unionid = wx.getStorageSync('thisCode');
    this.setData({aaFlag:false})
    wx.showLoading({title: '加载中...',})
    http._post('Coupon/coupon_list',{type:type,unionid:unionid},res=>{
      let data = res.data;
      if(data.status == 1){
        this.setData({
          cardBagArr:data.info.coupon_list,
          aaFlag: true,
          data:{
            name:'暂无'+this.data.exchangeArr[this.data.exchangeIndex]+'的优惠券信息'
          }
        })
      }
    },res=>{})
  },
  tabarChangeBtn(e){
    let index = http.dataIndex(e)[0];
    if(index==1){
      http.showModal('敬请期待',false,()=>{})
      return
    }
    let tabFlag = index==0?true:false;
    this.setData({tabFlag:tabFlag})
    if(index==1){
      
    }
  },
  exchange: function(e) {
    let index = Number(e.detail.value);
    this.cardBagFn(index);
    this.setData({
      exchangeIndex: e.detail.value,
      
    })
  },
  ewmPayNav(e){
    let thisId = http.dataIndex(e)[1];
    wx.redirectTo({
      url: "/pages/payewm/payewm?type=1&coupon_id="+thisId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu();
  },

  // 点击展开文字
  openTxtBtn(e){
    let index = http.dataIndex(e)[0];
    let cardArr = this.data.cardArr;
    cardArr[index].g = !cardArr[index].g;
    this.setData({cardArr:cardArr})
  },
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

})